package com.wei.duowan.bbs.ui.activity;

import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.wei.duowan.bbs.App;
import com.wei.duowan.bbs.R;
import com.wei.duowan.bbs.presenter.BasePresenter;
import com.wei.duowan.bbs.ui.adapter.BaseRecyclerViewAdapter;
import com.wei.duowan.bbs.ui.adapter.BaseViewHolder;

import java.util.Arrays;

import butterknife.Bind;

/**
 * 作者：赵若位
 * 时间：2019/10/17 10:53
 * 联系方式：1070138445
 * 功能：字体设置
 */
public class FontSizeActivity extends BaseActivity
{

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;


    private BaseRecyclerViewAdapter mAdapter;


    @Override
    protected BasePresenter createPresenter()
    {
        return null;
    }

    @Override
    protected int getLayoutID()
    {
        return R.layout.activity_font_size;
    }

    @Override
    protected void initView()
    {
        setTitle(R.string.content_font_size);
        setFinish();
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new BaseRecyclerViewAdapter<String>(this, R.layout.layout_font_size)
        {
            private int mPosition = 0;

            @Override
            protected void convert(int position, @Nullable BaseViewHolder holder, @Nullable String s)
            {
                View line = holder.setText(R.id.tv_title, s)
                        .setImageResource(R.id.img_check, R.mipmap.navigationbar_checkbox_active)
                        .setVisibility(R.id.img_check, position == mPosition ? View.VISIBLE : View.INVISIBLE)
                        .setOnClickListener(R.id.tv_title, view ->
                        {
                            if (position != mPosition)
                            {
                                mPosition = position;
                                notifyDataSetChanged();
                            }
                        })
                        .getView(R.id.tv_line);
                ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) line.getLayoutParams();
                params.setMargins(position == mList.size() - 1 ? 0 : App.getResource().getDimensionPixelOffset(R.dimen.dp_12), 0, 0, 0);
                line.setLayoutParams(params);
            }
        };
        mAdapter.bindRecyclerView(mRecyclerView);

        mAdapter.setNewData(Arrays.asList(new String[]{
                "大",
                "中",
                "小"
        }));
    }

}
